package jeecg.business.service.impl.site;

import java.util.List;

import jeecg.business.entity.site.SiteEntity;
import jeecg.business.entity.site.SiteWordEntity;
import jeecg.business.service.site.SiteServiceI;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("siteService")
@Transactional
public class SiteServiceImpl extends CommonServiceImpl implements SiteServiceI {
	public String [] getSelectetId(String keywordid){
		String sql = " select siteid from nms_site_word where keywordid = '"+keywordid+"'";
		List<String> idlist = getJdbcTemplate().queryForList(sql, String.class);
		if(idlist != null){
			return idlist.toArray(new String[0]);
		}
		return null;
	}
	public void assignSite(String keywordid , String keys){
		String [] keyarray = keys.split(",");
		SiteWordEntity siteWord = null;
		for(String key : keyarray){
			if(getJdbcTemplate().queryForInt(" select count(1) from nms_site_word where keywordid = '"+keywordid+"' and siteid = '"+key+"'")==0){
				siteWord = new SiteWordEntity();
				siteWord.setKeywordid(keywordid);
				siteWord.setSiteid(key);
				save(siteWord);
			}
		}
	}
	public void delSite(String keywordid , String keys){
		keys = "'"+keys.replace(",", "','")+"'";
		getJdbcTemplate().execute(" delete from nms_site_word where keywordid = '"+keywordid+"' and siteid in ("+keys+")");
	}
	
	public List<SiteEntity> findFetch(String keywordid){
		String hql = " select s from SiteEntity s ,SiteWordEntity sw where sw.siteid = s.id and sw.keywordid = '"+keywordid+"' and qyzt = '1'";
		return findByQueryString(hql);
	}
	
	
}